package com.qbccn.blog.config.exception;

import com.qbccn.blog.dto.ResponseCode;
import com.qbccn.blog.dto.ResponseResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 * @author linke
 * @date 2019-12-24 下午 22:58
 * @description controller 异常处理
 */
@RestControllerAdvice
public class ControllerException {

    @ExceptionHandler(NoHandlerFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public final ResponseResult noHandlerFoundException(NoHandlerFoundException ex) {
        return new ResponseResult(ResponseCode.API_NOT_EXIST, "不存在的api");
    }

    @ExceptionHandler(Exception.class)
    public final ResponseResult noHandlerFoundException(Exception ex) {
        return new ResponseResult(ResponseCode.OK, ex.toString());
    }

}
